home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / amiga.trm < prev    next >
Text File  |  1993-09-15  |  10KB  |  328 lines

  1. /*
  2.  * $Id: amiga.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - amiga.trm */
  7. /*
  8.  * Copyright (C) 1991, 1992
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *   Amiga Custom Screen
  26.  *
  27.  * AUTHORS
  28.  *   Carsten Steger
  29.  * 
  30.  *   Pat R. Empleo      Slightly modified for Aztec C v5.2a (beta); sort of
  31.  *   08/27/91           supports overscan; for large WB 2.0 virtual screens,
  32.  *                      we limit the plot size so we don't have to scroll
  33.  *                      around (not fun).
  34.  *
  35.  *   Carsten Steger     Modified to support Kickstart 2.0.
  36.  *   09/11/91           Opens a text overscan screen when used with WB 2.0.
  37.  *                      Discerns between NTSC and PAL Amigas when used with
  38.  *                      WB 1.3 and lower.
  39.  *
  40.  *   Pat R. Empleo      Defined some 2.0 stuff in order to get Aztec C to
  41.  *   09/20/91           work with Carsten's new code (see above).  When
  42.  *                      KS/WB 2.0 support gets implemented in Aztec C, this
  43.  *                      kludge will get deleted! 
  44.  *                      (Aztec C release 5.2 beta)
  45.  *
  46.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  47.  * 
  48.  */
  49.  
  50. #ifdef AMIGA_AC_5
  51. #include <intuition/intuitionbase.h>
  52. #include <intuition/screens.h>
  53. #include <graphics/text.h>
  54. #include <graphics/gfxbase.h>
  55. #else
  56. /* You will have to use the Kickstart 2.0 header files for this to compile */
  57. #include <exec/types.h>
  58. #include <intuition/intuitionbase.h>
  59. #include <graphics/gfxbase.h>
  60. #include <proto/intuition.h>
  61. #include <proto/graphics.h>
  62. #include <proto/exec.h>
  63. #include <proto/diskfont.h>
  64. #endif
  65.  
  66. extern char *getenv();
  67. #ifndef AMIGA_AC_5
  68. extern char *strchr();
  69. #endif
  70.  
  71. #define AMIGA_XMAX 640
  72. #define AMIGA_YMAX 512
  73.  
  74. #define AMIGA_VCHAR (12)
  75. #define AMIGA_HCHAR (8)
  76. #define AMIGA_VTIC (AMIGA_YMAX/80)
  77. #define AMIGA_HTIC (AMIGA_XMAX/80)
  78. /* The origin is in the upper left hand corner, so we have to translate */
  79. /* and flip the coordinates: */
  80. #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
  81.  
  82.  
  83. struct IntuitionBase *IntuitionBase;
  84. struct GfxBase *GfxBase;
  85. struct Library *DiskfontBase;
  86. static struct TextAttr AMIGA_Font = {
  87.   "topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT
  88. };
  89. static struct TextFont *AMIGA_TextFont;
  90. static struct NewScreen AMIGA_NewScreen = {
  91.   0,0,AMIGA_XMAX,AMIGA_YMAX,4,15,0,HIRES|LACE,
  92.   CUSTOMSCREEN|SCREENBEHIND|SCREENQUIET,NULL,NULL,NULL,NULL
  93. };
  94. static struct Screen *AMIGA_Screen;
  95. static UWORD AMIGA_Colors [] = {
  96.   0x000,0xfff,0xbbb,0x0f0,0xf00,0x00f,0x3ca,0xf0f,
  97.   0x94d,0x0ff,0x82f,0xff0,0x0af,0xc5e,0xfa2,0xf44
  98. };
  99. static int AMIGA_slinetype;
  100. static enum JUSTIFY AMIGA_justify = LEFT;
  101. static unsigned int AMIGA_ymax,AMIGA_xmax; 
  102. static WORD AMIGA_cwd,AMIGA_cht,AMIGA_bsl,AMIGA_vadj;
  103. static struct TagItem AMIGA_ScrTagList[] = {
  104.   {SA_Overscan,OSCAN_TEXT},{TAG_DONE,0}
  105. };
  106.  
  107.  
  108. AMIGA_reset()
  109. {
  110.   if (AMIGA_TextFont != NULL) CloseFont(AMIGA_TextFont);
  111.   if (DiskfontBase != NULL) CloseLibrary(DiskfontBase);
  112.   if (AMIGA_Screen != NULL) CloseScreen(AMIGA_Screen);
  113.   if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  114.   if (GfxBase != NULL) CloseLibrary(GfxBase);
  115.   AMIGA_TextFont = NULL;
  116.   DiskfontBase = NULL;
  117.   AMIGA_Screen = NULL;
  118.   IntuitionBase = NULL;
  119.   GfxBase = NULL;
  120. }
  121.  
  122.  
  123. AMIGA_init()
  124. {
  125.   static char fontname[80],*gnufont,*search;
  126.   static int fsize;
  127.   static char *test_str =
  128.     " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  129.   static WORD test_len,test_pxl;
  130.  
  131.  
  132. #ifdef AMIGA_SC_6_1
  133.   /* Install exit trap in case of abnormal termination (see below). */
  134.   int AMIGA_exit();
  135.   if (!onexit(&AMIGA_exit)) {
  136.     fprintf(stderr,"Couldn't set exit trap\n");
  137.     exit(20);
  138.   }
  139. #endif
  140.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0);
  141.   if (GfxBase == NULL) {
  142.     fprintf(stderr,"No Graphics-Library\n");
  143.     AMIGA_reset();
  144.     exit(20);
  145.   }
  146.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0);
  147.   if (IntuitionBase == NULL) {
  148.     fprintf(stderr,"No Intuition-Library\n");
  149.     AMIGA_reset();
  150.     exit(20);
  151.   }
  152.   if (IntuitionBase->LibNode.lib_Version <= 34) {
  153.     /* We compute the vertical resolution for those poor NTSC-souls   :-)   */
  154.     if (GfxBase->DisplayFlags & PAL) AMIGA_ymax = 512;
  155.     else AMIGA_ymax = 400;
  156.     AMIGA_xmax = 640;
  157.     AMIGA_NewScreen.Width = AMIGA_xmax;
  158.     AMIGA_NewScreen.Height = AMIGA_ymax;
  159.     AMIGA_Screen = OpenScreen(&AMIGA_NewScreen);
  160.     if (AMIGA_Screen == NULL) {
  161.       fprintf(stderr,"No Screen\n");
  162.       AMIGA_reset();
  163.       exit(20);
  164.     }
  165.   } else {
  166.     /* Kickstart 2.0 support */
  167.     AMIGA_NewScreen.Width = STDSCREENWIDTH;
  168.     AMIGA_NewScreen.Height = STDSCREENHEIGHT;
  169.     AMIGA_Screen = OpenScreenTagList(&AMIGA_NewScreen,AMIGA_ScrTagList);
  170.     if (AMIGA_Screen == NULL) {
  171.       fprintf(stderr,"No Screen\n");
  172.       AMIGA_reset();
  173.       exit(20);
  174.     }
  175.     AMIGA_xmax = AMIGA_Screen->Width;
  176.     AMIGA_ymax = AMIGA_Screen->Height;
  177.   }
  178.   term_tbl[term].xmax = AMIGA_xmax;
  179.   term_tbl[term].ymax = AMIGA_ymax;
  180.   gnufont = getenv("GNUFONT");
  181.   if (gnufont != NULL ) {
  182.     search = strchr(gnufont,'/');
  183.     if (search != NULL) {
  184.       *search++ = '\0';
  185.       strncpy(fontname,gnufont,74);
  186.       strcat(fontname,".font");
  187.       sscanf(search,"%d",&fsize);
  188.       /* Avoid opening "diskfont.library" if a built-in font is desired */
  189.       if ((strcmp("topaz.font",fontname) == 0) &&
  190.         ((fsize == TOPAZ_EIGHTY) || (fsize == TOPAZ_SIXTY))) {
  191.         AMIGA_Font.ta_Name = fontname;
  192.         AMIGA_Font.ta_YSize = fsize;
  193.         AMIGA_Font.ta_Style = FS_NORMAL;
  194.         AMIGA_Font.ta_Flags = FPF_ROMFONT;
  195.         AMIGA_TextFont = OpenFont(&AMIGA_Font);
  196.         if (AMIGA_TextFont != NULL) 
  197.           SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  198.       } else {
  199.         DiskfontBase = OpenLibrary("diskfont.library",0);
  200.         if (DiskfontBase != NULL) {
  201.           AMIGA_Font.ta_Name = fontname;
  202.           AMIGA_Font.ta_YSize = fsize;
  203.           AMIGA_Font.ta_Style = FS_NORMAL;
  204.           AMIGA_Font.ta_Flags = FPF_ROMFONT|FPF_DISKFONT;
  205.           AMIGA_TextFont = OpenDiskFont(&AMIGA_Font);
  206.           if (AMIGA_TextFont != NULL)
  207.             SetFont(&AMIGA_Screen->RastPort,AMIGA_TextFont);
  208.         }
  209.       }
  210.     }
  211.   }
  212.   /* Width of characters: This works better for proportional fonts than */
  213.   /* AMIGA_Screen->RastPort.TxWidth + AMIGA_Screen->RastPort.TxSpacing */
  214.   test_len = strlen(test_str);
  215.   test_pxl = TextLength(&AMIGA_Screen->RastPort,test_str,test_len);
  216.   AMIGA_cwd = test_pxl / test_len;
  217.   AMIGA_cht = AMIGA_Screen->RastPort.TxHeight; /* Height of characters */
  218.   AMIGA_bsl = AMIGA_Screen->RastPort.TxBaseline; /* Reference line */
  219.   /* Amount by which characters have to be shifted upwards to be */
  220.   /* vertically justified: */
  221.   AMIGA_vadj = AMIGA_bsl / 2;
  222.   term_tbl[term].v_char = AMIGA_cht + 4; /* So lines won't be too close */
  223.   term_tbl[term].h_char = AMIGA_cwd;
  224.   LoadRGB4(&AMIGA_Screen->ViewPort,AMIGA_Colors,16);
  225.   RemakeDisplay();
  226.   AMIGA_slinetype = 1;
  227.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  228.   SetDrMd(&AMIGA_Screen->RastPort,JAM1);
  229. }
  230.  
  231.  
  232. AMIGA_text()
  233. {
  234.   char c;
  235.  
  236.   c = getc(stdin);
  237.   ungetc(c,stdin);
  238.   ScreenToBack(AMIGA_Screen);
  239. }
  240.  
  241.  
  242. AMIGA_graphics()
  243. {
  244.   SetRast(&AMIGA_Screen->RastPort,0);
  245.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  246.   ScreenToFront(AMIGA_Screen);
  247. }
  248.  
  249.  
  250. AMIGA_move(x,y)
  251. unsigned int x,y;
  252. {
  253.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  254.   Move(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  255. }
  256.  
  257.  
  258. AMIGA_vector(x,y)
  259. unsigned int x,y;
  260. {
  261.   if ((x>=AMIGA_xmax) || (y>=AMIGA_ymax)) return;
  262.   Draw(&AMIGA_Screen->RastPort,x,AMIGA_VTF(y));
  263. }
  264.  
  265.  
  266. AMIGA_linetype(linetype)
  267. int linetype;
  268. {
  269.   if (linetype >= 13) linetype %= 13;
  270.   if (linetype < -2) linetype = -2;
  271.   AMIGA_slinetype = linetype+3;
  272.   SetAPen(&AMIGA_Screen->RastPort,AMIGA_slinetype);
  273. }
  274.  
  275.  
  276. AMIGA_put_text(x,y,str)
  277. unsigned int x,y;
  278. char *str;
  279. {
  280.   LONG len,tx_len;
  281.   WORD xmin,xmax,ymin,ymax;
  282.  
  283.   len = strlen(str);
  284.   tx_len = TextLength(&AMIGA_Screen->RastPort,str,len);
  285.   switch (AMIGA_justify) {
  286.     case LEFT:
  287.       xmin = x;
  288.       xmax = x + tx_len;
  289.       break;
  290.     case CENTRE:
  291.       xmin = x - tx_len / 2;
  292.       xmax = x + tx_len - tx_len / 2; /* aviod roundoff errors ! */
  293.       break;
  294.     case RIGHT:
  295.       xmin = x - tx_len;
  296.       xmax = x;
  297.       break;
  298.   }
  299.   ymin = AMIGA_VTF(y) - AMIGA_vadj;
  300.   ymax = ymin + AMIGA_cht;
  301.   /* Check if character-string lies completely within the screen: */
  302.   if ((xmax >= AMIGA_xmax) || (ymin < 0) || (ymax >= AMIGA_ymax)) return;
  303.   Move(&AMIGA_Screen->RastPort,xmin,ymin+AMIGA_bsl);
  304.   Text(&AMIGA_Screen->RastPort,str,len);
  305. }
  306.  
  307.  
  308. int AMIGA_justify_text(mode)
  309. enum JUSTIFY mode;
  310. {
  311.   AMIGA_justify = mode;
  312.   return TRUE;
  313. }
  314.  
  315.  
  316. /* This function is mainly included if the program terminates abnormally */
  317. /* and the screen and libraries are still open. It closes down all opened */
  318. /* libraries and screens. This happens e.g. when loading "bivariat.demo" */
  319. /* and the stack is smaller than 120000 bytes. */
  320. #ifdef AMIGA_SC_6_1
  321. int AMIGA_exit(rc)
  322. int rc;
  323. {
  324.   AMIGA_reset();
  325.   return rc;
  326. }
  327. #endif
  328.